
package term_project;

import java.awt.Dimension;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JTabbedPane;


public class ChatWindow extends JFrame
{
    //TODO:
    //      - Remove/Add Users to the chat
    //      - Emoticon parsing
    //      - Receiving a message
    //      - Whispers

    
    protected JTabbedPane chats;                                                // Chat tabs
    protected ArrayList<Chat> chatList;      // Holds the users friends list
    public ComputerUser user;                // The logged in user
    private MainWindow parent;
    
    public ChatWindow(ComputerUser User, MainWindow Parent)
    {
        super("Chats");
        Message message;    // Welcome Message
        user = User;
        initComponents();
        parent = Parent;
    }
    

    
    private void initComponents()
    {
        chatList = new ArrayList();
        chats = new JTabbedPane();
        add(chats);
        this.setMinimumSize(new Dimension(600,400));
        pack();
    }

    public void addChat(Chat chat)
    {
        if(!chatList.contains(chat))
        {
            chatList.add(chat);
            ChatPanel chatP = new ChatPanel(user, chat, this);
            chats.addTab(chatP.getTitle(), chatP);
            chats.setSelectedIndex(chats.indexOfComponent(chatP));
        }
        else
        {
            chats.setSelectedIndex(chatList.indexOf(chat));
        }
    }
    public void reloadParent()
    {
        parent.loadLists();
    }
    public void removeChat(Chat chat)
    {
        if(chat != null)
        {
            if(chatList.contains(chat))
            {
                chats.remove(chatList.indexOf(chat));
                chatList.remove(chat);
                if(chats.getTabCount() == 0)
                {
                    this.setVisible(false);
                }
            }
        }
    }
    private void removeChat()
    {
        chats.remove(chats.getSelectedIndex());
    }

}
